﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using AdinZ.Web.UI;
using System.Text.RegularExpressions;
/**
* @Author: AdinZ
* @Q  Q : 1454269
* @Email:adinz@adinz.com
* @Created: 2014/4/3 17:58:15
* */
namespace Web
{
    public partial class Default : BasePage
    {

        protected void Page_Load(object sender, EventArgs e)
        {
            string vHtml = "";
            bool vWebPageCache = AdinZ.Common.ConfigHelper.GetConfigBool("WebPageCache"); //判断是否启用了页面缓存
            if (vWebPageCache == false)
            {
                vHtml = Fun_GetIndexContent(0);
            }
            else
            {
                int vCacheTime = AdinZ.Common.ConfigHelper.GetConfigInt("CacheTime");
                string indexCacheKey = AdinZ.Common.ConfigHelper.GetConfigString("CacheKey") + "_default_" + 0;
                object indexCacheInfo = AdinZ.Common.DataCache.GetCache(indexCacheKey);

                //判断缓存是否存在
                if (indexCacheInfo == null)
                {
                    vHtml = Fun_GetIndexContent(0);
                    AdinZ.Common.DataCache.SetCache(indexCacheKey, (object)vHtml, DateTime.Now.AddSeconds(vCacheTime), TimeSpan.Zero);
                }
                else
                {
                    vHtml = indexCacheInfo.ToString();
                }
            }
            vHtml = Function.Fun_UrlRewriter(vHtml);
            Response.Write(vHtml);
        }


        private string Fun_GetIndexContent(int byPage)
        {
            string vTemplateUrl = ("default.html");
            Template wt = new Template();
            wt.Load_Template(vTemplateUrl);
            wt.vPage = byPage;
            wt.vContent = Regex.Replace(wt.vContent, Regex.Escape("{sys:sitehost}"), siteConfig.SiteHost, RegexOptions.IgnoreCase);
            wt.vContent = Regex.Replace(wt.vContent, Regex.Escape("{sys:title}"), siteConfig.WebName, RegexOptions.IgnoreCase);
            wt.vContent = Regex.Replace(wt.vContent, Regex.Escape("{sys:keyword}"), siteConfig.Keyword, RegexOptions.IgnoreCase);
            wt.vContent = Regex.Replace(wt.vContent, Regex.Escape("{sys:description}"), siteConfig.Description, RegexOptions.IgnoreCase);
            wt.vContent = Regex.Replace(wt.vContent, Regex.Escape("{sys:seotitle}"), seoConfig.SeoTitle, RegexOptions.IgnoreCase);
            wt.vContent = Regex.Replace(wt.vContent, Regex.Escape("{sys:keywords}"), seoConfig.IndexKeywords, RegexOptions.IgnoreCase);
            wt.vContent = Regex.Replace(wt.vContent, Regex.Escape("{sys:description}"), seoConfig.IndexDescription, RegexOptions.IgnoreCase);
            wt.vContent = Regex.Replace(wt.vContent, Regex.Escape("{sys:filehost}"), siteConfig.FileHost, RegexOptions.IgnoreCase);
            wt.vContent = Regex.Replace(wt.vContent, Regex.Escape("{sys:sitepath}"), "<a href=\"/\">首页</a>", RegexOptions.IgnoreCase);

            //wt.Parser_MyTag(); //自定义标签
            wt.Parser_List();
            wt.Parser_Page();
            wt.Parser_IF();
            return wt.vContent;
        }
        protected string Update(string str)
        {
            return str;
        }

    
    }
}